#ifndef QMEMERYDATAVIEW_H
#define QMEMERYDATAVIEW_H

#include <QTreeWidget>
#include <QItemDelegate>
#include <QMap>

namespace CORELIB
{
    class StyledBar;
}

class QMemeryDataView;
class QMemeryDelegate: public QItemDelegate
{
    Q_OBJECT
public :
    QMemeryDelegate(QMemeryDataView* parent):m_listView(parent){}
    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void    setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
protected:
    QMemeryDataView   *m_listView;
};

class QMemeryDataView : public QTreeWidget
{
    Q_OBJECT
public:
    explicit QMemeryDataView(QWidget *parent = 0);
    
    bool    isGroupItem(QTreeWidgetItem *item)const ;
protected slots:
    void    refresh();

    void    add();
    void    remove();

    void    removeData(QObject* obj);

    void    addData(QObject* obj);
protected:
    friend class QMemeryDelegate;
protected:
    void    clear();
    void    drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const;
protected:
    void    resizeEvent(QResizeEvent *event);
    void    mousePressEvent(QMouseEvent *event);
signals:
    
public slots:

protected:
    CORELIB::StyledBar  *m_styledBar;
    QIcon                                                   m_expandIcon;
    QMap<QString,QTreeWidgetItem*>                          m_items;
    QMap<QString,QTreeWidgetItem*>                          m_groups;
    QMap<QTreeWidgetItem*,QObject*>                         m_itemToObject;
    
};

#endif // QMEMERYDATAVIEW_H
